Skip to content

feat(documentation): source documentation extraction (#1654) - #1966

Open
dekobon wants to merge 266 commits into
mainfrom
feat/1654-documentation
Open

dekobon wants to merge 266 commits into
mainfrom
feat/1654-documentation

Conversation

@dekobon

@dekobon dekobon commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements source-level documentation extraction for big-code-analysis across all 25 LANG variants, completing epic #1654 and all 28 child issues (#1655–#1682):

  • Public API (#1680): Exposes big_code_analysis::documentation and Ast::documentation(&self, context, options) -> Result<DocumentationIndex<'_>, CollectionError> with #[non_exhaustive] result/option/error types, chainable builders (with_logical_filename, with_profile, with_unbound_evidence, with_directive_evidence), Display + std::error::Error (with Error::source chaining), and count-only Debug views.
  • 23 Source/Dialect Adapters (Capability::Partial) & 2 Helper Grammars (Capability::NoDeclarationModel):
    • Rust (#1664, Profile::Rust): Line/block outer (///, /**) and inner (//!, /*!) doc comments and #[doc = ...] attributes, macro-free value extraction, and unindent cleanup with exact forward source mappings.
    • Python (#1665, Profile::PyDocstring): PEP 257 module, class, and function/method body docstrings (Primary and Additional), implicit string concatenation, and inspect.cleandoc-style cleanup with exact forward source mappings.
    • Java, Kotlin, & Groovy (#1666, Profile::Javadoc, Profile::Kdoc, Profile::Groovydoc): Javadoc, KDoc (including nested block comments), and Groovydoc extraction, package-info.java package owners, Java/Groovy multi-declarator SlotRole::Field slots, and Kotlin single-name SlotRole::Property slots.
    • C# (#1667, Profile::CsharpXml): /// and /** XML documentation comments and multi-declarator field, constant, and event-field SlotRole::Field slots.
    • PHP (#1668, Profile::BcaPhpSource): /** PHPDoc comments and single-name property (SlotRole::Property) and constant (SlotRole::Binding) slots.
    • JavaScript & Mozjs (#1669, Profile::Jsdoc): /** JSDoc comments, export/statement wrappers, anonymous default exports, and first simple variable_declarator bindings.
    • TypeScript & TSX (#1670, Profile::BcaTypescriptSource): /** TSDoc/JSDoc comments, export and declare wrappers, internal_module (namespace), anonymous default exports, first simple variable_declarator bindings, and using / await using assignments.
    • C, C++, Mozcpp, & Objective-C (#1671, Profile::Doxygen): Leading (/**, /*!, ///, //!) and trailing (/**<, /*!<, ///<, //!<) Doxygen comments, @file / \file gatherer separation, trailing enumerator-comma resolution, and single-declaration C++ template_declaration and linkage_specification (extern "C") wrappers.
    • Go (#1672, Profile::GoDoc): Go doc comment runs, package clauses, grouped const / var / type specifications (SlotRole::Constant, SlotRole::Variable, SlotRole::Type, SlotRole::Field), and multi-name field_declaration slots.
    • Ruby (#1673, Profile::Yard): Leading # YARD comment runs, visibility-wrapped method definitions (private def f, protected def f, public def f, module_function def f, private_class_method def self.f), and attr_reader / attr_writer / attr_accessor / attr SlotRole::Property slots.
    • Lua (#1674, Profile::Ldoc): --- and --[[-- LDoc runs, standalone structural tag classification (@module, @script, @function, @table, @field, @section, @type, etc.), named table field (SlotRole::Field) slots, single-name assignment_statement / variable_declaration owners, and return_statement owners.
    • Perl (#1675, Profile::Pod): Streaming POD block recognition and file-document extraction with doubt scanning and legacy LOC isolation.
    • Elixir (#1676, Profile::Elixir): @moduledoc, @doc, and @typedoc module attributes, boolean false suppression, string/sigil/heredoc literal rendering, and following-definition attachment.
    • Bash (#1677, Profile::Shdoc): Leading # shdoc comment blocks above function_definition declarations, #! / # shellcheck directive separation, and shell lexical boundary scanning.
    • Tcl (#1678, Profile::Ruff): Ruff-style leading #ruff and procedure-body initial comment runs on top-level proc declarations with Tcl command/brace scanning.
    • iRules (#1679, Profile::Irules): Leading # comment runs on top-level when_event and procedure declarations with Tcl command/brace/continuation scanning.
    • Helper grammars (Ccomment, Preproc): Explicit Capability::NoDeclarationModel outcomes.
  • Legacy Metric Isolation: Zero changes to tests/repositories/big-code-analysis-output (5fbe03bf) or .role-coverage-observed.txt.

Child Issues

Closes #1654, #1655, #1656, #1657, #1658, #1659, #1660, #1661, #1662, #1663, #1664, #1665, #1666, #1667, #1668, #1669, #1670, #1671, #1672, #1673, #1674, #1675, #1676, #1677, #1678, #1679, #1680, #1681, #1682

Verification (a0c7da4a)

  • make pre-commit: BCA_GATE: pass (gate=pre-commit) (8,562 tests passed, 0 failed)
  • make self-scan-baseline-fresh: 0 added, 0 removed, 0 worsened, 0 improved
  • make fuzz-check: 20/20 fuzz tests passed + nightly ASan fuzz targets built cleanly
  • make bench-source & make bench-scaling: combined gate: 0 performance failures
  • anchor_check.py: manifests=77 cases=1972 problems=0

Implement D03 marker binding evidence with independent source candidates, native profile hooks, final-member selection and canonical raw occurrences. Migrate shared and Rust LOC atomically to ordered legacy events.

Validate exact row/timing/cache counters, Doxygen gathering and conditional siblings, nested and macro source context. Selected replay: 390 outputs, zero drift. All 140 scaling probes pass; make pre-commit reports BCA_GATE: pass. Tracked perturbation manifest supports the clean-checkpoint sweep.
Register byte-exact tagged seeds for all language dispatch outcomes and source, identity, pending, qualification, and mapping edge cases. Reuse the held Ast source in ordinary fanout and keep typed cancellation provenance in the tagged path.

Checkpoint before the parent-assigned heavy validation slot: formatting, seed metadata checks, and lightweight lints pass; Cargo builds/tests, fuzz campaigns, the full gate, and parent reviews remain pending.
Fix digest formatting and clippy findings discovered in the first executable check. Qualify Tcl/iRules EOF recovery and the explicitly pending source-gap selection without changing seed bytes. Apply all six independent documentation-review corrections and add a finite mutation manifest.
The RDoc-style rule read `##` as a two-byte marker for every profile
but iRules, while `###` kept two hashes. YARD's on_comment strips the
whole leading run (`^(#+)\s{0,1}`), so `### Heading` is `Heading`;
shdoc's description rule removes one `#`, so `## Heading` is
`# Heading`. YARD now strips the run and every other profile one `#`.
A long comment spanning rows kept the dashes of a `--]]` closer as
text. LDoc's tools.grab_block_comment drops the whole row that holds
the closer, so the source view now does the same, and the source
opener reads the same kept text: a block whose only text sits on its
closing row is no document, as LDoc discards it. The legacy opener
keeps reading the whole comment.
A blank row between a `---` block and the item below it detached the
block, while LDoc's lexer gives each line comment its LF and
parse_file skips the whole space token that follows before it asks
item_follows. The source rules now say which rows stand below a run:
any later row for LDoc and the next row elsewhere, so Go and Bash still
detach at a blank row, and an intervening comment still separates two
LDoc blocks. RunEnd keeps reporting the blank row itself.
Comment rows on consecutive rows joined one YARD document whatever
their columns, so a commented-out line above an indented doc block
leaked into it. YARD's on_comment appends a row only at the previous
row's column. The source rules now refuse such a join for Ruby; Go,
Bash and Lua still ignore columns, and the legacy LOC run is
unchanged. YARD's reset of the column after `=end` is left unmodelled:
a pinned LOC test counts the joined source run.
The source view took a Ruby target only from the sibling on the row
below a run. YARD's insert_comments asks each statement for a block
ending on the row above it, then two rows above, then on its own row,
and add_comment refuses a block whose last line is `#-`.

A run now documents a statement up to two rows below it, a lone
trailing comment documents the statement that starts on its row unless
that statement has a block above, and a `#-` block documents nothing.
A chain of trailing comments shares one answer, which a walk memo
records so the chain costs one walk. A trailing comment that YARD
hands on to a later node stays unattached; the source view does not
guess that node. Go and Bash still detach at a blank row.
A body comment on the row of a handler's opening brace was reported as
definitively unattached, while Tcl's lead block (`proc f {} {# a`) and
Ruff read it as the first row of the body text, and the contract gives
iRules body docs Tcl's boundary. Accept such a comment, after blanks
alone, as the first initial-body row, so the block gets the pending
body assessment instead of unattached evidence.
The Tcl reader composes only a procedure body's own rows, yet Ruff!
reads the rows of the body text and so also reads a `#ruff` row nested
in a braced command body, as the manual's sample::character_at does.
Such a text was reported complete with no assessment. The walk now
notes the first nested `#ruff` row that starts its line, as Ruff!
trims and reads it, and leaves a pending Composition assessment on the
procedure.
Two Tcl forms the contract promises produced nothing and no
assessment: TclOO method, constructor and destructor bodies in a
literal class body, and Ruff namespace preambles. iRules body docs,
shdoc @file and Python attribute docstrings already pend, and
consumers are told to check pending assessments. Each carrier now
leaves a pending Occurrence assessment: the first comment row of a
TclOO body, and the value word of a `variable` or `set` of
`_ruff_preamble`.
One row per decision of the Ruby, Lua, Bash, Tcl and iRules
documentation fixes: each mutant restores the old behaviour, or drops
a guard of the new one, and names the tests that must fail for it.
A Sphinx `#:` comment documents the binding below it, which the Python
adapter cannot project yet, so it produced nothing: no document and no
assessment, though the book tells consumers to check pending
assessments. Report it as a pending Owner assessment, as an attribute
docstring already is. The LOC test that counts the source view's
assessments for python-runs.py now expects two; its legacy rows are
unchanged.
The Ruby, Lua, Bash, Tcl and iRules adapter fixes change what the
Unreleased documentation entry promises for those languages.
The adapter fixes moved metrics in the Ruby, Lua, Tcl, iRules and
positional-run code; regenerated with make
self-scan-write-baseline-headroom.
audit-tests found two tests that could pass for the wrong reason:

- profile_names_are_lowercase_hyphenated_words read a hand-written
  list, so a new `Profile` variant with a capitalized name passed (a
  probe variant `Extra` => "Extra" did). An exhaustive match now stops
  the test compiling until the list names every variant.
- The fuzz recipe test accepted any failure when the target list omits
  the documentation target; it now requires the recipe's own message,
  which a reworded message fails in 14 subtests.
From the simplify review of the adapter fixes:
- YARD's two-row window was spelled twice; `yard_reaches` now serves
  the positional hook and the trailing-comment chain, and one
  `trailing_holder` replaces the duplicated holder test.
- The iRules brace-row check copied `row`; both now call `row_after`,
  which also gives the brace case `row`'s coverage of the comment.
- The Tcl Ruff collector reads a command's first word once, compares
  kind ids rather than kind names, scans a line prefix through the
  budgeted `trim_start`, and updates the open procedure in place.
- A stale `trivially_copy_pass_by_ref` allow is gone.
Perturbation rows that anchored on the old spellings keep their
mutants' meaning.
The collector test helpers only borrow their options, so take
`&DocumentationOptions` instead of carrying a needless_pass_by_value
allow whose stated reason was untrue (go_tests cloned the same value
for each call). Also share the two-document fixture and drop asserts
the iRules behaviour table already pins.
- The map-origin containment check scanned every fragment piece per
  origin; the pieces are sorted and disjoint, so binary-search them,
  and fill one reused buffer through `fragment_ranges`, which the
  property and its test now share.
- Compute the unfinished-Kotlin condition once per input, and restore
  the profile match order.
- The producer case now travels only in a token file the driver
  deletes after each run, so an exported variable names nothing.
- The seed generator names its corpus and registry paths once.
`CombinedReport` held a source report and an abandoned-run error that
could never both be set; `source: Option<Result<SourceReport,
HarnessError>>` makes that state unrepresentable and drops the check
that policed it. The length-axis shape test counts nodes with
tree-sitter's `descendant_count`.
The anchor test read a fixed list of directories, which is how the
bench manifests went unchecked. It now takes every JSON object in the
checkout whose `cases` rows carry an `old` anchor, outside hidden,
build, corpus and submodule trees: the same 84 manifests today, and
any later one wherever it lives.
The package check reads the grammar path dependencies from the root
manifest instead of a hand copy, and the fuzz recipe test reuses its
MAKE_VARIABLES list.
`reject-stored-scalar-split` added a scalar-boundary requirement to
the map partition check, which caught the per-piece split a divided
scalar used to get. Since eb5f867 a divided scalar maps as one run
and `maps::validate` requires scalar boundaries itself, so the mutant
adds a check that always holds; the sweep reports it uncaught.
The simplify pass guarded `irules_brace_row` with `above.is_none()` in
its caller, which pushed `irules_initial_body_rows` past its cognitive
and Halstead headroom. The guard is redundant: a comment runs to its
row's end, so once a row is accepted every later comment starts below
the brace's row, and the row comparison rejects it before any budgeted
scan. Refresh the baseline entries the pass improved.
- The perturbation anchor test now fails on a JSON file it cannot parse,
  except the two JSONC files the check-json hook exempts, and on a file
  named like a manifest that holds no anchored cases; a broken manifest
  used to drop its rows silently.
- fuzz-make-test.py drops FUZZ_* from the child make environment: GNU
  make exports command-line overrides into recipes, so the MAKEFLAGS
  scrub alone let `make pre-commit FUZZ_RUNS=7` fail the recipe tests.
  A listing that prints every name and then fails is now tested too.
- The fuzz origin check tests both ends of a fragment, so it no longer
  depends on sorted input to stay sound, and a decoded-origin twin
  covers the arm the copied twin could not.
- The bench's abandoned-cell verdict moves from the untestable bench
  main into combined::source_outcome, with a test per mode.
- Correct the fuzzing guide's Kotlin exception, the package check's
  --offline rationale and the fixture README.
A comment trailing the first row of a multi-row statement (`def m # c`,
`class C < B # c`) is a child of that statement, so the previous-sibling
rule found only the method name or the superclass and attached nothing.
YARD walks statements in pre-order and asks each for a comment on its
own row last, so the outermost statement starting on the row takes it.
The trailing hook now returns that ancestor with its own chain, and the
run is scoped by the target's parent rather than the comment's.
Ruff! reads a procedure's body text, so a `#ruff` row inside an inner
`proc` is a row of every enclosing body too. Only the innermost open
procedure was checked, so the outer one kept Complete text with no
Composition assessment. Each open procedure now records the first row
it holds and passes it to the enclosing one when it closes, which notes
a row once rather than once per open procedure.
YARD's insert_comments takes a block only when on_comment left it
non-empty, and on_comment never stores a magic comment, so both are
passed over: a lone `#` or `#####` row documented a statement with an
empty text, and either one kept the statement from its trailing
comment. A block add_comment refuses stays, so a statement below one
row of code still finds it and takes no comment. on_comment strips
`^(#+)\s{0,1}`, so the one blank after the marker may be a tab.
The first-file rule asked whether an earlier block held text by its raw
spelling, while the block itself is read without a long comment's
closing row, as tools.grab_block_comment drops it. A long comment whose
only text sits on that row therefore stopped the next block from
documenting the file. The source lane now reads the earlier block the
same way; the legacy run keeps its pinned reading.
trailing-header-target-asked-with-comment-chain asked a header holder's
target with the comment's chain instead of its own. Ruby's answer is
memoised per node and reads the chain only through the YARD scope fold,
and the two chains differ only by nodes on the holder's own header row,
none of which changes that fold, so no input tells them apart.
tcl-comments-nested-in-a-command-are-rows called the free children and
node helpers, and lua-prose-only-in-opener-member an older
read_with_budget arity; both stopped compiling after earlier refactors
on this branch, and the anchor test checks only that `old` matches, so
neither was flagged. Each now uses the current API with its meaning
kept.
The rationale cited `bca metrics` timings, whose 0.34 linear fit shows
process overhead swamping the signal. Watched in the harness with the
released 2.6.1 scan restored, loc/doxygen-inline-code-spans fits 1.98
and fails its 1.50 bound; with the linear scan it fits 0.98.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment